package 死锁程序;

public class TestDeadLock implements Runnable {
    private A a = new A();
    private B b = new B();

    private void init() throws InterruptedException {
        Thread.currentThread().setName("主线程");
        a.waitMethod(b);
    }

    @Override
    public void run() {
        Thread.currentThread().setName("副线程");
        try {
            b.waitMethod(a);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) throws InterruptedException {
        TestDeadLock testDeadLock = new TestDeadLock();
        Thread thread = new Thread(testDeadLock);
        thread.start();
        testDeadLock.init();
    }
}
